package sceneGraph;

import javax.media.j3d.Transform3D;
import javax.vecmath.AxisAngle4f;
import javax.vecmath.Color3f;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3f;

public class Planet extends AbstractPlanet implements ISceneObject {

	private Point3f orbitPoint;

	public Planet(float radius, Point3f pos, Color3f kDiffuse, Color3f kSpecular, Color3f kAmbient, float nShineness, boolean isSun, Vector3f orbitAxis,
			float orbitSpeed, Point3f orbitPoint, String textureFilePath, String heightMapFilePath) {
		super(radius, pos, kDiffuse, kSpecular, kAmbient, nShineness, isSun, orbitAxis, orbitSpeed, textureFilePath, heightMapFilePath);
		this.orbitPoint = new Point3f(orbitPoint);
	}

	public Point3f getOrbitPoint() {
		return orbitPoint;
	}

	@Override
	public void accept(Visitor visitor) {
		visitor.visit(this);
	}

	@Override
	public void recalcAbsPosition() {
		AxisAngle4f axis = new AxisAngle4f(getOrbitAxis(), getAngle() / 180 * (float) Math.PI);

		Point3f relativePos = new Point3f();
		relativePos.sub(getPosition(), orbitPoint);

		Transform3D transform = new Transform3D();
		transform.setRotation(axis);
		transform.setTranslation(new Vector3f(orbitPoint));

		absPos = new Point3f(relativePos);
		transform.transform(absPos);

		for (Moon m : getMoons()) {
			m.setParentAbsPos(absPos);
			m.recalcAbsPosition();
		}
	}
}
